package com.freemyleft.left.zapp.ui.recycler;

import com.chad.library.adapter.base.entity.MultiItemEntity;

import java.io.Serializable;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
import java.util.LinkedHashMap;

/**
 * Created by zuo on 2017/9/26.
 * 这是我最后的大绝招了  你再试试  不行真没办法了...
 * 不行就把这个注释掉再试试   试两次  把这个序列化注销了 我还玩个篱笆
 * 我模拟器从昨天就连不上网了 能解决下不
 *
 */

public class MultipleItemEntity implements MultiItemEntity
        , Serializable
{
//    private final ReferenceQueue<LinkedHashMap<Object, Object>> ITEM_QUEUE = new ReferenceQueue<>();
    private final LinkedHashMap<Object, Object> MULTIPLE_FIELDS = new LinkedHashMap<>();
//    private final SoftReference<LinkedHashMap<Object, Object>> FIELDS_REFERENCE = new SoftReference<>(MULTIPLE_FIELDS, ITEM_QUEUE);

    public MultipleItemEntity(LinkedHashMap<Object, Object> fields) {
        MULTIPLE_FIELDS.putAll(fields);
    }

    public static MultipleItemEntityBuilder builder() {
        return new MultipleItemEntityBuilder();
    }

    @Override
    public int getItemType() {
        return (int) MULTIPLE_FIELDS.get(MultipleFields.ITEM_TYPE);
    }

    public final <T> T getField(Object key) {
        return (T) MULTIPLE_FIELDS.get(key);
    }



    public final MultiItemEntity setField(Object key, Object value) {
        MULTIPLE_FIELDS.put(key, value);
        return this;
    }

}
